﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DataAccessLayer;
using GlobalObjects;
using System.Collections.Generic;


namespace DataAccessLayerTests
{
    [TestClass]
    public class NotificationEntityTests
    {
        [TestMethod]
        public void insertNotification_DAL_valid()
        {
            //arrange
            int userId = 1093;
            int deviceId = 2088;
            string reason = "upper_limit_triggered";
            int sensorId = 3372;
            NotificationEntity en = new NotificationEntity();
            //action
            en.insertNotification_DAL(userId, deviceId, reason, sensorId);
        }
        [TestMethod]
        public void insertNotification_DAL_valid_differentReason()
        {
            //arrange
            int userId = 1090;
            int deviceId = 1057;
            string reason = "triggered";
            int sensorId = 2318;
            NotificationEntity en = new NotificationEntity();
            //action
            en.insertNotification_DAL(userId, deviceId, reason, sensorId);
        }
        [TestMethod]
        [ExpectedException(typeof(System.Data.Entity.Infrastructure.DbUpdateException))]
        public void insertNotification_DAL_invalid_userId()
        {
            //arrange
            int userId = 11;
            int deviceId = 1057;
            string reason = "lost";
            int sensorId = 2318;
            NotificationEntity en = new NotificationEntity();
            //action
            en.insertNotification_DAL(userId, deviceId, reason, sensorId);
        }
        [TestMethod]
        [ExpectedException(typeof(System.Data.Entity.Infrastructure.DbUpdateException))]
        public void insertNotification_DAL_invalid_deviceId()
        {
            //arrange
            int userId = 1090;
            int deviceId = 211324;
            string reason = "lost";
            int sensorId = 2318;
            NotificationEntity en = new NotificationEntity();
            //action
            en.insertNotification_DAL(userId, deviceId, reason, sensorId);
        }
        [TestMethod]
        [ExpectedException(typeof(System.Data.Entity.Infrastructure.DbUpdateException))]
        public void insertNotification_DAL_invalid_duplicatedIDs()
        {
            //arrange
            int userId = 1090;
            int deviceId = 1057;
            int sensorId = 2318;
            string reason = "lost";
            NotificationEntity en = new NotificationEntity();
            //action
            en.insertNotification_DAL(userId, deviceId, reason, sensorId);
        }
        [TestMethod]
        public void removeNotification_DAL_valid()
        {
            //arrange
            int id = 1008;
            NotificationEntity en = new NotificationEntity();
            //action
            en.removeNotification_DAL(id);
        }
        [TestMethod]
        [ExpectedException(typeof(System.Data.Entity.Infrastructure.DbUpdateException))]
        public void removeNotification_DAL_invalid()
        {
            //arrange
            int userId = 11;
            int deviceId = 10;
            NotificationEntity en = new NotificationEntity();
            //action
           // en.removeNotification_DAL(userId, deviceId);
        }
        [TestMethod]
        public void getNotifications_DAL_valid()
        {
            //arrange
            int userId = 1090;
            NotificationEntity en = new NotificationEntity();
            //action
            List<Notification> result = en.getNotifications_DAL(userId);
            //assert
            Assert.AreEqual(result .Count,1);
        }
        [TestMethod]
        public void getNotifications_DAL_invalid()
        {
            //arrange
            int userId = 176;
            NotificationEntity en = new NotificationEntity();
            //action
            List<Notification> result = en.getNotifications_DAL(userId);
            //assert
            Assert.AreEqual(result.Count, 0);
        }

        [TestMethod]
        public void getNotificationsByFilter_DAL_valid_lost()
        {
            //arrange
            int userId = 1178;
            NotificationEntity en = new NotificationEntity();
            //action
            List<Notification> result = en.getNotificationsByFilter_DAL(userId,"lost");
            //assert
            Assert.AreEqual(result.Count, 1);
        }
        [TestMethod]
        public void getNotificationsByFilter_DAL_invalid_randomString()
        {
            //arrange
            int userId = 1178;
            NotificationEntity en = new NotificationEntity();
            //action
            List<Notification> result = en.getNotificationsByFilter_DAL(userId, "abcd");
            //assert
            Assert.AreEqual(result.Count, 0);
        }
    }
}
